/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.client.control;

import com.edu.kamai.webservice.client.WSScoreClient;
import com.edu.kamai.webservice.score.Score;
import java.util.List;

/**
 *
 * @author xyzhu
 */
public class scoreControl {
    private static List<String> netList;
    private static String message;
    private static WSScoreClient wsScoreClient;
    
    public static String getMessage() {
        return message;
    }

    public static void setMessage(String message) {
        scoreControl.message = message;
    }

    public static List<String> getNetList() {
        return netList;
    }

    public static void setNetList(List<String> netList) {
        scoreControl.netList = netList;
    }

    public static void setServer(){
        try{
            wsScoreClient = new WSScoreClient();
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static int updateScoreByContestIDAndStudentID(int cID,String uID,
            int scores,int finishTime,int type){
        int ans;
        
        try{
            ans = wsScoreClient.updateScoreByContestIDAndStudentID(cID, uID, 
                    scores, finishTime, type);
            if (ans == 1) {
                message = "Update Score OK!";
            } else {
                message = "Update Score Failed!";
            }
        }catch(Exception ex){
            ans = 0;
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return ans;
    }
    
    public static List<Score> getScoreByUserID(String uID){
        List<Score> scores = null;
        
        try{
            scores = wsScoreClient.getScoreByUserID(uID);
            if(scores.size() == 0 || scores == null){
                message = "no scores!";
            }else{
                message = "all " + scores.size() + " scores";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return scores;
    }
    
    
}
